#include "datastructures.h"

#include <stdlib.h>

double ControlValue::max = 0;
double ControlValue::min = 0;
double ControlValue::avg = 0;

//================================================
Point * Triangle::next_point(Point *rel_p)
{
    if (rel_p == p1)
        return p2;
    if (rel_p == p2)
        return p3;
    if (rel_p == p3)
        return p1;
}

//================================================
Point * Triangle::prev_point(Point *rel_p)
{
    if (rel_p == p1)
        return p3;
    if (rel_p == p2)
        return p1;
    if (rel_p == p3)
        return p2;
}


double Triangle::calculateArea()
{
    return fabs((p1->x*(p2->y-p3->y)+p2->x*(p3->y-p1->y)+p3->x*(p1->y-p2->y))/2.0);
}

//================================================
double Triangle::area()
{
    return area_;
}

//================================================
Point Triangle::center()
{
    double x = (p1->x + p2->x + p3->x)/3.0;
    double y = (p1->y + p2->y + p3->y)/3.0;
    return Point(x,y,param,0);
}

//================================================
Edge * Triangle::getEdge(Point *p1, Point *p2)
{
    for (int i =0; i<edges.size(); i++)
    {
        Edge *e = edges[i];
        if ((e->p1 == p1 && e->p2 == p2) || (e->p1 == p2 && e->p2 == p1))
            return e;
    }
    return NULL;
}
